package com.zsj;
import java.io.File;
/**
 * @author zsj
 * @date 2023/5/16 11:55
 */
public class RemoveDir {
        static int iFile = 0;
        public static void main(String[] args) {
            // dir_str清理文件夹的路径
            String dir_str = "D:\\do";
            File dir = new File( dir_str );
            clear( dir );
            System.out.println( "清理成功。" );
            System.out.println( "共清理了" + iFile + "个空文件夹" );
        }
        public static void clear( File dir ) {
            File[] dirs = dir.listFiles();
            for (int i = 0; i < dirs.length; i++) {
                if (dirs[i].isDirectory()) {
                    clear(dirs[i]);
                }
            }
            if (dir.isDirectory() && dir.delete())
                iFile++;
            System.out.println(dir + "清理成功");

        }
}
